<?php
	require 'conn.php';

	class shop{
		function addshop($name, $title, $address, $telephone, $email, $latitude, $longitude, $description, $details, $type, $area_id) {
						
			$sql = "SELECT name FROM shop where name='$name'";
			$result = mysql_query($sql);
	
			if ($myrow = mysql_fetch_row($result)) {
				echo("<script language=javascript>alert('已经存在该名称的店铺！'); history.go(-1)</script>");
				exit;
			}
			$currentTime = time();
			$lastEditTime = time();
			$query = "INSERT INTO shop(name, title, address, description, telephone, createtime, email, latitude, longitude,lastedittime,details,type,area_id)"
						."VALUES('$name','$title','$address','$description','$telephone','$currentTime','$email','$latitude','$longitude','$lastEditTime','$details','$type','$area_id')";
			
			$result = mysql_query($query) or die("插入出现错误：". mysql_errno());
			$rowid = mysql_insert_id();
			if ($rowid > 0) {
				echo "成功添加店铺：".$name."<hr><p>";
				return $rowid;
			}
			else {
				echo("<script language=javascript>alert('添加新店铺失败！'); history.go(-1)</script>");
			}
		}
		
		function editshop($id, $name, $title, $address, $telephone, $email, $latitude, $longitude, $description, $details,$area_id){
			$lastEditTime = time();
			$query = "UPDATE shop SET name='$name',title='$title',address='$address',description='$description', details='$details' ,telephone='$telephone',email='$email',latitude='$latitude',longitude='$longitude',lastedittime='$lastEditTime',area_id='$area_id' WHERE shop_id=".$id;
						
			mysql_query($query);

			echo "成功修改店铺：".$name."<hr><p>";
		}
		
		function deleteshop($shopid) {
			;
		}
		
		function listshops() {
			;
		}
	}
?>